package com.recommend.controller.admin;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import com.recommend.domain.UserDomain;
import com.recommend.service.UserService;

/**
 * Created by lw.
 */
@RestController
@RequestMapping("/admin/user")
public class UserController {
    private final static Logger logger = LoggerFactory.getLogger(LoginController.class);

    @Resource
    private UserService userService;

    @RequestMapping(value = "/getAllUser", method = RequestMethod.POST)
    @ResponseBody
    public List<UserDomain> getAllUser(){
        logger.info("==============================get all user============");
        return userService.getAllUser();
    }

    @RequestMapping(value = "/searchUser", method = RequestMethod.POST)
    @ResponseBody
    public List<UserDomain> searchUser(UserDomain userDomain){
        logger.info("=========admin: name={}, gender={}, age={}, occupation={}============", userDomain.getName(), userDomain.getGender(), userDomain.getAge(), userDomain.getOccupation());
        return userService.searchUser(userDomain);
    }

    @RequestMapping(value = "/getUserByAccount", method = RequestMethod.POST)
    @ResponseBody
    public int getUserByAccount(@RequestParam("account") String account){
        logger.info("=========admin: account={}============", account);
        return userService.searchUserByAccount(account);
    }

    @RequestMapping(value = "/register", method = RequestMethod.POST)
    @ResponseBody
    public int addUser(UserDomain userDomain){
        logger.info("=========admin: account={}============", userDomain.getAccount());
        return userService.addUser(userDomain);
    }

    @RequestMapping(value = "/modifyUser", method = RequestMethod.POST)
    @ResponseBody
    public int modifyUser(UserDomain userDomain){
        logger.info("=========admin: name={}, gender={}, age={}, occupation={}============", userDomain.getName(), userDomain.getGender(), userDomain.getAge(), userDomain.getOccupation());
        return userService.updateUser(userDomain);
    }
}
